/**********************************************************************************************************
** 驱动文件：	ups-YMK3300.c
** 驱动类型：	ups
** 设备名称：	UPS监测
** 设备型号：	YMK3300
** 设备品牌：	科士达
** 设备协议：	Modbus-RTU
** 驱动描述：	适用于科士达YMK3300系列三进三出高频模块化UPS。
** 生成日期：	2019-07-18 12:03:16
**********************************************************************************************************/
#include "Includes.h"


/**********************************************************************************************************
* 定义设备数据点变量结构
**********************************************************************************************************/
typedef struct{
	Var inputUA;								//输入A相电压
	Var inputUB;								//输入B相电压
	Var inputUC;								//输入C相电压
	Var inputFreq;								//输入频率
	Var inputIA;								//输入A相电流
	Var inputIB;								//输入B相电流
	Var inputIC;								//输入C相电流
	Var inputCOSA;								//输入A相功率因数
	Var inputCOSB;								//输入B相功率因数
	Var inputCOSC;								//输入C相功率因数
	Var outputUA;								//输出A相电压
	Var outputUB;								//输出B相电压
	Var outputUC;								//输出C相电压
	Var outputFreq;								//输出频率
	Var outputIA;								//输出A相电流
	Var outputIB;								//输出B相电流
	Var outputIC;								//输出C相电流
	Var outputPA;								//输出A相有功功率
	Var outputPB;								//输出B相有功功率
	Var outputPC;								//输出C相有功功率
	Var outputLoadRateA;						//输出A相负载率
	Var outputLoadRateB;						//输出B相负载率
	Var outputLoadRateC;						//输出C相负载率
	Var APhaseLoadPeakRatio;					//输出A相负载峰值比
	Var BPhaseLoadPeakRatio;					//输出B相负载峰值比
	Var CPhaseLoadPeakRatio;					//输出C相负载峰值比
	Var BypassUA;								//旁路A相电压
	Var BypassUB;								//旁路B相电压
	Var BypassUC;								//旁路C相电压
	Var BypassFreq;								//旁路频率
	Var PositiveBatteryVoltage;					//正组电池电压
	Var NegativeBatteryVoltage;					//负组电池电压
	Var PositiveBatteryDischargeCurrent;		//正组电池放电电流
	Var NegativeBatteryDischargeCurrent;		//负组电池放电电流
	Var PositiveBatteryChargeCurrent;			//正组电池充电电流
	Var NegativeBatteryChargeCurrent;			//负组电池充电电流
	Var BatteryCapacity;						//电池容量
	Var BatteryRemainingTime;					//电池后备时间
	Var BatteryTemperature;						//电池温度
	Var AmbientTemperature;						//环境温度
	Var BatteryDischargeTime;					//电池放电时间
	Var RunningStatus;							//运行状态
	Var InputAirSwitchStatus;					//输入空开状态
	Var OutputAirSwitchStatus;					//输出空开状态
	Var MaintenanceBypassAirSwitchStatus;		//维修旁路空开状态
	Var BypassAirSwitchStatus;					//旁路空开状态
	Var BypassCabinetBypassAirSwitchStatus;		//旁路柜旁路空开状态
	Var ExternalOutputAirSwitchStatus;			//外部输出空开状态
	Var InverterHost;							//逆变主机
	Var InverterStandby;						//逆变待机
	Var LBSSystemActivation;					//LBS系统激活
	Var BatterySelfTest;						//电池自检
	Var BatteryCharging;						//电池充电
	Var PositiveBatteryEquallyCharged;			//正组电池均充
	Var NegativeBatteryEquallyCharged;			//负组电池均充
	Var RectifierStatus;						//整流器状态
	Var RectifierCurrentLimit;					//整流器限流
	Var InputPowerStatus;						//输入供电状态
	Var InputPowerMode;							//输入供电模式
	Var InverterOnOffStatus;					//逆变开关机状态
	Var UPSPowerSupplyStatus;					//UPS供电状态
	Var DiscontinuousSwitchPrompt;				//间断切换提示
	Var InadequateStartupCapacity;				//启动容量不足
	Var OverloadDelayShutdown;					//过载延时到关机
	Var LoadShockSwitchingBypass;				//负载冲击切旁路
	Var ParallelSwitchingBypass;				//并机系统转旁路
	Var BatteryLowVoltageShutdown;				//电池电压低关机
	Var SwitchingTimesExhausted;				//切换次数到
	Var RectifierFailure;						//整流器故障
	Var InverterFailure;						//逆变器故障
	Var AuxiliaryPowerFailure;					//辅助电源故障
	Var FanFailure;								//风扇故障
	Var InputThyristorFailure;					//输入晶闸管故障
	Var InverterThyristorFailure;				//逆变晶闸管故障
	Var BypassThyristorFailure;					//旁路晶闸管故障
	Var FuseBreak;								//熔丝断
	Var BusVoltageAbnormal;						//母线电压异常
	Var InitializationFailure;					//初始化故障
	Var BatteryThyristorFailure;				//电池晶闸管故障
	Var ChargerFailure;							//充电器故障
	Var ParallelFailure;						//并机故障
	Var InvalidBoot;							//开机无效
	Var ITnverterDCComponentLarge;				//逆变直流分量过大
	Var InputPhaseReverse;						//输入电压相序反
	Var InputMissingZeroPhase;					//输入缺零
	Var BypassReverse;							//旁路反序
	Var BatteryDamage;							//电池损坏
	Var BatteryOverheating;						//电池过温
	Var Overload;								//过载
	Var ParallelOverload;						//并机过载
	Var BatteryVoltageAlarm;					//电池电压低/高
	Var BatteryUndervoltagePrealarm;			//电池欠压预告警
	Var MainsFrequencyAbnormal;					//市电频率异常
	Var MainsVoltageAbnormal;					//市电电压异常
	Var BypassSuperTracking;					//旁路超跟踪
	Var BypassOvercurrent;						//旁路过流
	Var FireAlarm;								//火灾报警
	Var SmokeAlarm;								//烟雾报警
}Data_Struct;									//定义变量结构


/**********************************************************************************************************
* 设备数据点变量属性声明
**********************************************************************************************************/
const static Var_Property_Def var_attr[] = {
	{
		FLOAT,
		0,
		READONLY,
		"inputUA",
		"输入A相电压",
		"V",
		"输入A相电压",
		0,
		0,
		"输入A相电压过高",
		"输入A相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputUB",
		"输入B相电压",
		"V",
		"输入B相电压",
		0,
		0,
		"输入B相电压过高",
		"输入B相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputUC",
		"输入C相电压",
		"V",
		"输入C相电压",
		0,
		0,
		"输入C相电压过高",
		"输入C相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputFreq",
		"输入频率",
		"Hz",
		"输入频率",
		0,
		0,
		"输入频率过高",
		"输入频率过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputIA",
		"输入A相电流",
		"A",
		"输入A相电流",
		0,
		0,
		"输入A相电流过高",
		"输入A相电流过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputIB",
		"输入B相电流",
		"A",
		"输入B相电流",
		0,
		0,
		"输入B相电流过高",
		"输入B相电流过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputIC",
		"输入C相电流",
		"A",
		"输入B相电流",
		0,
		0,
		"输入B相电流过高",
		"输入B相电流过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputCOSA",
		"输入A相功率因数",
		"",
		"输入A相功率因数",
		0,
		0,
		"输入A相功率因数过高",
		"输入A相功率因数过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputCOSB",
		"输入B相功率因数",
		"",
		"输入B相功率因数",
		0,
		0,
		"输入B相功率因数过高",
		"输入B相功率因数过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"inputCOSC",
		"输入C相功率因数",
		"",
		"输入C相功率因数",
		0,
		0,
		"输入C相功率因数过高",
		"输入C相功率因数过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputUA",
		"输出A相电压",
		"V",
		"输出A相电压",
		0,
		0,
		"输出A相电压过高",
		"输出A相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputUB",
		"输出B相电压",
		"V",
		"输出B相电压",
		0,
		0,
		"输出B相电压过高",
		"输出B相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputUC",
		"输出C相电压",
		"V",
		"输出C相电压",
		0,
		0,
		"输出C相电压过高",
		"输出C相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputFreq",
		"输出频率",
		"Hz",
		"输出频率",
		0,
		0,
		"输出频率过高",
		"输出频率过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputIA",
		"输出A相电流",
		"A",
		"输出A相电流",
		0,
		0,
		"输出A相电流过高",
		"输出A相电流过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputIB",
		"输出B相电流",
		"A",
		"输出B相电流",
		0,
		0,
		"输出B相电流过高",
		"输出B相电流过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputIC",
		"输出C相电流",
		"A",
		"输出C相电流",
		0,
		0,
		"输出C相电流过高",
		"输出C相电流过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputPA",
		"输出A相有功功率",
		"KW",
		"输出A相有功功率",
		0,
		0,
		"输出A相有功功率过高",
		"输出A相有功功率过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputPB",
		"输出B相有功功率",
		"KW",
		"输出B相有功功率",
		0,
		0,
		"输出B相有功功率过高",
		"输出B相有功功率过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputPC",
		"输出C相有功功率",
		"KW",
		"输出C相有功功率",
		0,
		0,
		"输出C相有功功率过高",
		"输出C相有功功率过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputLoadRateA",
		"输出A相负载率",
		"%",
		"输出A相负载率",
		0,
		0,
		"输出A相负载率过高",
		"输出A相负载率过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputLoadRateB",
		"输出B相负载率",
		"%",
		"输出B相负载率",
		0,
		0,
		"输出B相负载率过高",
		"输出B相负载率过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"outputLoadRateC",
		"输出C相负载率",
		"%",
		"输出C相负载率",
		0,
		0,
		"输出C相负载率过高",
		"输出C相负载率过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"APhaseLoadPeakRatio",
		"输出A相负载峰值比",
		"",
		"输出A相负载峰值比",
		0,
		0,
		"输出A相负载峰值比过高",
		"输出A相负载峰值比过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BPhaseLoadPeakRatio",
		"输出B相负载峰值比",
		"",
		"输出B相负载峰值比",
		0,
		0,
		"输出B相负载峰值比过高",
		"输出B相负载峰值比过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"CPhaseLoadPeakRatio",
		"输出C相负载峰值比",
		"",
		"输出C相负载峰值比",
		0,
		0,
		"输出C相负载峰值比过高",
		"输出C相负载峰值比过低",
		0.000,
		0.000
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassUA",
		"旁路A相电压",
		"V",
		"旁路A相电压",
		0,
		0,
		"旁路A相电压过高",
		"旁路A相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassUB",
		"旁路B相电压",
		"V",
		"旁路B相电压",
		0,
		0,
		"旁路B相电压过高",
		"旁路B相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassUC",
		"旁路C相电压",
		"V",
		"旁路C相电压",
		0,
		0,
		"旁路C相电压过高",
		"旁路C相电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"BypassFreq",
		"旁路频率",
		"Hz",
		"旁路频率",
		0,
		0,
		"旁路频率过高",
		"旁路频率过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"PositiveBatteryVoltage",
		"正组电池电压",
		"V",
		"正组电池电压",
		0,
		0,
		"正组电池电压过高",
		"正组电池电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"NegativeBatteryVoltage",
		"负组电池电压",
		"V",
		"负组电池电压",
		0,
		0,
		"负组电池电压过高",
		"负组电池电压过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"PositiveBatteryDischargeCurrent",
		"正组电池放电电流",
		"A",
		"正组电池放电电流",
		0,
		0,
		"正组电池放电电流过高",
		"正组电池放电电流过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"NegativeBatteryDischargeCurrent",
		"负组电池放电电流",
		"A",
		"负组电池放电电流",
		0,
		0,
		"负组电池放电电流过高",
		"负组电池放电电流过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"PositiveBatteryChargeCurrent",
		"正组电池充电电流",
		"A",
		"正组电池充电电流",
		0,
		0,
		"正组电池充电电流过高",
		"正组电池充电电流过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"NegativeBatteryChargeCurrent",
		"负组电池充电电流",
		"A",
		"负组电池充电电流",
		0,
		0,
		"负组电池充电电流过高",
		"负组电池充电电流过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"BatteryCapacity",
		"电池容量",
		"%",
		"电池容量",
		0,
		0,
		"电池容量过高",
		"电池容量过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"BatteryRemainingTime",
		"电池后备时间",
		"分钟",
		"电池后备时间",
		0,
		0,
		"电池后备时间过高",
		"电池后备时间过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"BatteryTemperature",
		"电池温度",
		"℃",
		"电池温度",
		0,
		0,
		"电池温度过高",
		"电池温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"AmbientTemperature",
		"环境温度",
		"℃",
		"环境温度",
		0,
		0,
		"环境温度过高",
		"环境温度过低",
		0,
		0
	},
	{
		FLOAT,
		0,
		READONLY,
		"BatteryDischargeTime",
		"电池放电时间",
		"分钟",
		"电池放电时间",
		0,
		0,
		"电池放电时间过高",
		"电池放电时间过低",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"RunningStatus",
		"运行状态",
		"",
		"UPS运行状态：0-初始化；1-待机状态；2-无输出状态；3-旁路状态；4-市电状态；5-电池状态；6-电池自检状态；7-逆变启动中；8-经济模式；9-EPO状态；10-维护旁路模式；11-故障模式",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InputAirSwitchStatus",
		"输入空开状态",
		"",
		"输入空开状态：0-断开；1-闭合",
		0,
		0,
		"断开",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OutputAirSwitchStatus",
		"输出空开状态",
		"",
		"输出空开状态：0-断开；1-闭合",
		0,
		0,
		"断开",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MaintenanceBypassAirSwitchStatus",
		"维修旁路空开状态",
		"",
		"维修旁路空开状态：0-断开；1-闭合",
		0,
		0,
		"断开",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassAirSwitchStatus",
		"旁路空开状态",
		"",
		"旁路空开状态：0-断开；1-闭合",
		0,
		0,
		"断开",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassCabinetBypassAirSwitchStatus",
		"旁路柜旁路空开状态",
		"",
		"旁路柜旁路空开状态：0-断开；1-闭合",
		0,
		0,
		"断开",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ExternalOutputAirSwitchStatus",
		"外部输出空开状态",
		"",
		"外部输出空开状态：0-断开；1-闭合",
		0,
		0,
		"断开",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InverterHost",
		"逆变主机",
		"",
		"逆变主机：0-禁止；1-启用",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InverterStandby",
		"逆变待机",
		"",
		"逆变待机：0-禁止；1-启用",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"LBSSystemActivation",
		"LBS系统激活",
		"",
		"LBS系统激活：0-禁止；1-启用",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatterySelfTest",
		"电池自检",
		"",
		"电池自检：0-禁止；1-自检中",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryCharging",
		"电池充电",
		"",
		"电池充电：0-禁止；1-启用",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"PositiveBatteryEquallyCharged",
		"正组电池均充",
		"",
		"正组电池均充：0-禁止；1-启用",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"NegativeBatteryEquallyCharged",
		"负组电池均充",
		"",
		"负组电池均充：0-禁止；1-启用",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"RectifierStatus",
		"整流器状态",
		"",
		"整流器状态：0-停止；1-工作",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"RectifierCurrentLimit",
		"整流器限流",
		"",
		"整流器限流：0-无限流；1-限流中",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InputPowerStatus",
		"输入供电状态",
		"",
		"输入供电状态：0-不工作；1-工作",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InputPowerMode",
		"输入供电模式",
		"",
		"输入供电模式：0-电池供电；1-输入供电",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InverterOnOffStatus",
		"逆变开关机状态",
		"",
		"逆变开关机状态：0-关机；1-软启动；2-启动完毕未供电；3-正常供电中",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"UPSPowerSupplyStatus",
		"UPS供电状态",
		"",
		"UPS供电状态：0-均不供电；1-旁路供电；2-逆变供电",
		0,
		0,
		"",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"DiscontinuousSwitchPrompt",
		"间断切换提示",
		"",
		"间断切换提示：0-无告警；1-告警",
		0,
		0,
		"告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InadequateStartupCapacity",
		"启动容量不足",
		"",
		"启动容量不足：0-无告警；1-告警",
		0,
		0,
		"告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"OverloadDelayShutdown",
		"过载延时到关机",
		"",
		"过载延时到关机：0-无告警；1-告警",
		0,
		0,
		"告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"LoadShockSwitchingBypass",
		"负载冲击切旁路",
		"",
		"负载冲击切旁路：0-无告警；1-告警",
		0,
		0,
		"告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ParallelSwitchingBypass",
		"并机系统转旁路",
		"",
		"并机系统转旁路：0-无告警；1-告警",
		0,
		0,
		"告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryLowVoltageShutdown",
		"电池电压低关机",
		"",
		"电池电压低关机：0-无告警；1-告警",
		0,
		0,
		"告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"SwitchingTimesExhausted",
		"切换次数到",
		"",
		"切换次数到：0-无告警；1-告警",
		0,
		0,
		"告警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"RectifierFailure",
		"整流器故障",
		"",
		"整流器故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InverterFailure",
		"逆变器故障",
		"",
		"逆变器故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"AuxiliaryPowerFailure",
		"辅助电源故障",
		"",
		"辅助电源故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"FanFailure",
		"风扇故障",
		"",
		"风扇故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InputThyristorFailure",
		"输入晶闸管故障",
		"",
		"输入晶闸管故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InverterThyristorFailure",
		"逆变晶闸管故障",
		"",
		"逆变晶闸管故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassThyristorFailure",
		"旁路晶闸管故障",
		"",
		"旁路晶闸管故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"FuseBreak",
		"熔丝断",
		"",
		"熔丝断：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BusVoltageAbnormal",
		"母线电压异常",
		"",
		"母线电压异常：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InitializationFailure",
		"初始化故障",
		"",
		"初始化故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryThyristorFailure",
		"电池晶闸管故障",
		"",
		"电池晶闸管故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ChargerFailure",
		"充电器故障",
		"",
		"充电器故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ParallelFailure",
		"并机故障",
		"",
		"并机故障：0-无故障；1-故障",
		0,
		0,
		"故障",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InvalidBoot",
		"开机无效",
		"",
		"开机无效：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ITnverterDCComponentLarge",
		"逆变直流分量过大",
		"",
		"逆变直流分量过大：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InputPhaseReverse",
		"输入电压相序反",
		"",
		"输入电压相序反：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"InputMissingZeroPhase",
		"输入缺零",
		"",
		"输入缺零：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassReverse",
		"旁路反序",
		"",
		"旁路反序：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryDamage",
		"电池损坏",
		"",
		"电池损坏：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryOverheating",
		"电池过温",
		"",
		"电池过温：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"Overload",
		"过载",
		"",
		"过载：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"ParallelOverload",
		"并机过载",
		"",
		"并机过载：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryVoltageAlarm",
		"电池电压低/高",
		"",
		"电池电压低/高：0-无报警；1-高压报警；2-低压报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BatteryUndervoltagePrealarm",
		"电池欠压预告警",
		"",
		"电池欠压预告警：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MainsFrequencyAbnormal",
		"市电频率异常",
		"",
		"市电频率异常：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"MainsVoltageAbnormal",
		"市电电压异常",
		"",
		"市电电压异常：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassSuperTracking",
		"旁路超跟踪",
		"",
		"旁路超跟踪：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"BypassOvercurrent",
		"旁路过流",
		"",
		"旁路过流：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"FireAlarm",
		"火灾报警",
		"",
		"火灾报警：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	},
	{
		OCTSTR,
		0,
		READONLY,
		"SmokeAlarm",
		"烟雾报警",
		"",
		"烟雾报警：0-无报警；1-报警",
		0,
		0,
		"报警",
		"",
		0,
		0
	}
};


/**********************************************************************************************************
* 函数名称： static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
* 函数说明： 生成获取传感器数据指令
* 输入参数： 指令索引，传感器地址，变量结构体指针,以及指令缓存区指针,指令长度
* 返回参数： 无
**********************************************************************************************************/
static void cmd_fun(short index, int addr, void *data, char *cmd, short *len)
{
	switch(index)
	{
		case 0:
			cmd[0] = addr;
			cmd[1] = 0x04;
			cmd[2] = 0x75;								
			cmd[3] = 0x30;
			cmd[4] = 0x00;	
			cmd[5] = 0x29;
			*len = CRC16_Padding(cmd, 6);
			break;
		case 1:
			cmd[0] = addr;
			cmd[1] = 0x04;
			cmd[2] = 0x75;								
			cmd[3] = 0x80;
			cmd[4] = 0x00;	
			cmd[5] = 0x01;
			*len = CRC16_Padding(cmd, 6);			
			break;
		case 2:
			cmd[0] = addr;
			cmd[1] = 0x02;
			cmd[2] = 0x27;								
			cmd[3] = 0x10;
			cmd[4] = 0x00;	
			cmd[5] = 0x1F;
			*len = CRC16_Padding(cmd, 6);			
			break;
		case 3:
			cmd[0] = addr;
			cmd[1] = 0x02;
			cmd[2] = 0x27;								
			cmd[3] = 0x50;
			cmd[4] = 0x00;
			cmd[5] = 0x25;
			*len = CRC16_Padding(cmd, 6);			
			break;			
		default:
			break;
	}
}


/**********************************************************************************************************
* 函数名称： static int parse_fun(short index, int addr, void *data, char *buf, short len)
* 函数说明： 解析传感器响应的数据，并写入数据库
* 输入参数： 解析索引,传感器地址，变量结构体指针，以及响应数据缓存取指针，响应数据长度
* 返回参数： 返回解析结果，返回0成功，返回1失败
**********************************************************************************************************/
static int parse_fun(short index, int addr, void *data, char *buf, short len)
{
	const char *runnigmodel[] = {"初始化","待机状态","无输出状态","旁路状态","市电状态","电池状态","电池自检状态","逆变启动中","经济模式","EPO状态","维护旁路模式","故障模式"};
	union{
		unsigned short	dat16;
      	unsigned char  	dat8[2];
    }DAT16_8;						   //数据类型转换	
	Data_Struct	*d = (Data_Struct*)data;

	if(buf!=NULL && buf[0]==addr && len>0 )
	{	
		if(CRC16_Check(buf,len))
		{
			switch(index)
			{
				case 0:
					DAT16_8.dat8[1] = buf[3];
					DAT16_8.dat8[0] = buf[4];
					d->inputUA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[5];
					DAT16_8.dat8[0] = buf[6];
					d->inputUB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[7];
					DAT16_8.dat8[0] = buf[8];
					d->inputUC.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[9];
					DAT16_8.dat8[0] = buf[10];
					d->inputFreq.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[11];
					DAT16_8.dat8[0] = buf[12];
					d->inputIA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[13];
					DAT16_8.dat8[0] = buf[14];
					d->inputIB.value.fnum = DAT16_8.dat16*0.1;					
					DAT16_8.dat8[1] = buf[15];
					DAT16_8.dat8[0] = buf[16];
					d->inputIC.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[17];
					DAT16_8.dat8[0] = buf[18];
					d->inputCOSA.value.fnum = DAT16_8.dat16*0.01;
					DAT16_8.dat8[1] = buf[19];
					DAT16_8.dat8[0] = buf[20];
					d->inputCOSB.value.fnum = DAT16_8.dat16*0.01;
					DAT16_8.dat8[1] = buf[21];
					DAT16_8.dat8[0] = buf[22];
					d->inputCOSC.value.fnum = DAT16_8.dat16*0.01;
					
					DAT16_8.dat8[1] = buf[23];
					DAT16_8.dat8[0] = buf[24];
					d->outputUA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[25];
					DAT16_8.dat8[0] = buf[26];
					d->outputUB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[27];
					DAT16_8.dat8[0] = buf[28];
					d->outputUC.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[29];
					DAT16_8.dat8[0] = buf[30];
					d->outputFreq.value.fnum = DAT16_8.dat16*0.1;
					
					DAT16_8.dat8[1] = buf[31];
					DAT16_8.dat8[0] = buf[32];
					d->outputIA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[33];
					DAT16_8.dat8[0] = buf[34];
					d->outputIB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[35];
					DAT16_8.dat8[0] = buf[36];
					d->outputIC.value.fnum = DAT16_8.dat16*0.1;	

					DAT16_8.dat8[1] = buf[37];
					DAT16_8.dat8[0] = buf[38];
					d->outputPA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[39];
					DAT16_8.dat8[0] = buf[40];
					d->outputPB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[41];
					DAT16_8.dat8[0] = buf[42];
					d->outputPC.value.fnum = DAT16_8.dat16*0.1;						
					
					DAT16_8.dat8[1] = buf[43];
					DAT16_8.dat8[0] = buf[44];
					d->outputLoadRateA.value.fnum = DAT16_8.dat16*1.0;
					DAT16_8.dat8[1] = buf[45];
					DAT16_8.dat8[0] = buf[46];
					d->outputLoadRateB.value.fnum = DAT16_8.dat16*1.0;
					DAT16_8.dat8[1] = buf[47];
					DAT16_8.dat8[0] = buf[48];
					d->outputLoadRateC.value.fnum = DAT16_8.dat16*1.0;
					
					DAT16_8.dat8[1] = buf[49];
					DAT16_8.dat8[0] = buf[50];
					d->APhaseLoadPeakRatio.value.fnum = DAT16_8.dat16*0.01;
					DAT16_8.dat8[1] = buf[51];
					DAT16_8.dat8[0] = buf[52];
					d->BPhaseLoadPeakRatio.value.fnum = DAT16_8.dat16*0.01;
					DAT16_8.dat8[1] = buf[53];
					DAT16_8.dat8[0] = buf[54];
					d->CPhaseLoadPeakRatio.value.fnum = DAT16_8.dat16*0.01;
					
					DAT16_8.dat8[1] = buf[55];
					DAT16_8.dat8[0] = buf[56];
					d->BypassUA.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[57];
					DAT16_8.dat8[0] = buf[58];
					d->BypassUB.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[59];
					DAT16_8.dat8[0] = buf[60];
					d->BypassUC.value.fnum = DAT16_8.dat16*0.1;						

					DAT16_8.dat8[1] = buf[61];
					DAT16_8.dat8[0] = buf[62];
					d->BypassFreq.value.fnum = DAT16_8.dat16*0.1;

					DAT16_8.dat8[1] = buf[63];
					DAT16_8.dat8[0] = buf[64];
					d->PositiveBatteryVoltage.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[65];
					DAT16_8.dat8[0] = buf[66];
					d->NegativeBatteryVoltage.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[67];
					DAT16_8.dat8[0] = buf[68];
					d->PositiveBatteryDischargeCurrent.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[69];
					DAT16_8.dat8[0] = buf[70];
					d->NegativeBatteryDischargeCurrent.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[71];
					DAT16_8.dat8[0] = buf[72];
					d->PositiveBatteryChargeCurrent.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[73];
					DAT16_8.dat8[0] = buf[74];
					d->NegativeBatteryChargeCurrent.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[75];
					DAT16_8.dat8[0] = buf[76];
					d->BatteryCapacity.value.fnum = DAT16_8.dat16*1.0;
					DAT16_8.dat8[1] = buf[77];
					DAT16_8.dat8[0] = buf[78];
					d->BatteryRemainingTime.value.fnum = DAT16_8.dat16*1.0;
					DAT16_8.dat8[1] = buf[79];
					DAT16_8.dat8[0] = buf[80];
					d->BatteryTemperature.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[81];
					DAT16_8.dat8[0] = buf[82];
					d->AmbientTemperature.value.fnum = DAT16_8.dat16*0.1;
					DAT16_8.dat8[1] = buf[83];
					DAT16_8.dat8[0] = buf[84];
					d->BatteryDischargeTime.value.fnum = DAT16_8.dat16*1.0;
					break;
				case 1:
					DAT16_8.dat8[1] = buf[3];
					DAT16_8.dat8[0] = buf[4];
					d->RunningStatus.value.str = DAT16_8.dat16<12?runnigmodel[DAT16_8.dat16]:"未知";
					break;
				case 2:
					d->InputAirSwitchStatus.value.str					= buf[3]&0x01?"闭合":"断开";
					Set_Var_Status(&d->InputAirSwitchStatus,			  buf[3]&0x01?ON:OFF, NULL);
					d->OutputAirSwitchStatus.value.str					= buf[3]&0x02?"闭合":"断开";
					Set_Var_Status(&d->OutputAirSwitchStatus,			  buf[3]&0x02?ON:OFF, NULL);
					d->MaintenanceBypassAirSwitchStatus.value.str		= buf[3]&0x04?"闭合":"断开";
					Set_Var_Status(&d->MaintenanceBypassAirSwitchStatus,  buf[3]&0x04?ON:OFF, NULL);
					d->BypassAirSwitchStatus.value.str					= buf[3]&0x08?"闭合":"断开";
					Set_Var_Status(&d->BypassAirSwitchStatus,			  buf[3]&0x08?ON:OFF, NULL);
					d->BypassCabinetBypassAirSwitchStatus.value.str		= buf[3]&0x10?"闭合":"断开";
					Set_Var_Status(&d->BypassCabinetBypassAirSwitchStatus,buf[3]&0x10?ON:OFF, NULL);					
					d->ExternalOutputAirSwitchStatus.value.str			= buf[3]&0x20?"闭合":"断开";
					Set_Var_Status(&d->ExternalOutputAirSwitchStatus,	  buf[3]&0x20?ON:OFF, NULL);

					d->InverterHost.value.str							= buf[3]&0x40?"启用":"禁止";
					Set_Var_Status(&d->InverterHost,					  buf[3]&0x40?ON:OFF, NULL);
					d->InverterStandby.value.str						= buf[3]&0x80?"启用":"禁止";
					Set_Var_Status(&d->InverterStandby,					  buf[3]&0x80?ON:OFF, NULL);
					d->LBSSystemActivation.value.str					= buf[4]&0x01?"启用":"禁止";
					Set_Var_Status(&d->LBSSystemActivation,				  buf[4]&0x01?ON:OFF, NULL);
					d->BatterySelfTest.value.str						= buf[4]&0x02?"自检中":"禁止";
					Set_Var_Status(&d->BatterySelfTest,					  buf[4]&0x02?ON:OFF, NULL);
					d->BatteryCharging.value.str						= buf[4]&0x04?"启用":"禁止";
					Set_Var_Status(&d->BatteryCharging,					  buf[4]&0x04?ON:OFF, NULL);
					d->PositiveBatteryEquallyCharged.value.str			= buf[4]&0x08?"启用":"禁止";
					Set_Var_Status(&d->PositiveBatteryEquallyCharged,	  buf[4]&0x08?ON:OFF, NULL);
					d->NegativeBatteryEquallyCharged.value.str			= buf[4]&0x10?"启用":"禁止";
					Set_Var_Status(&d->NegativeBatteryEquallyCharged,	  buf[4]&0x10?ON:OFF, NULL);

					d->RectifierStatus.value.str						= buf[4]&0x20?"工作":"停止";
					Set_Var_Status(&d->RectifierStatus,					  buf[4]&0x20?ON:OFF, NULL);
					d->RectifierCurrentLimit.value.str					= buf[4]&0x40?"限流中":"无限流";
					Set_Var_Status(&d->RectifierCurrentLimit,			  buf[4]&0x40?ON:OFF, NULL);
					d->InputPowerStatus.value.str						= buf[4]&0x80?"工作":"不工作";
					Set_Var_Status(&d->InputPowerStatus,				  buf[4]&0x80?ON:OFF, NULL);
					d->InputPowerMode.value.str							= buf[5]&0x01?"输入供电":"电池供电";
					Set_Var_Status(&d->InputPowerMode,					  buf[5]&0x01?ON:OFF, NULL);
					
					if((buf[5]&0x06)==0x00){
						d->InverterOnOffStatus.value.str = "关机";
						Set_Var_Status(&d->InverterOnOffStatus, OFF, NULL);						
					}
					else if((buf[5]&0x06)==0x02){
						d->InverterOnOffStatus.value.str = "软启动";
						Set_Var_Status(&d->InverterOnOffStatus, ON, NULL);						
					}					
					else if((buf[5]&0x06)==0x04){
						d->InverterOnOffStatus.value.str = "启动完毕未供电";
						Set_Var_Status(&d->InverterOnOffStatus, ON, NULL);						
					}						
					else if((buf[5]&0x06)==0x06){
						d->InverterOnOffStatus.value.str = "正常供电中";
						Set_Var_Status(&d->InverterOnOffStatus, ON, NULL);						
					}

					if((buf[5]&0x18)==0x00){
						d->UPSPowerSupplyStatus.value.str = "均不供电";
						Set_Var_Status(&d->UPSPowerSupplyStatus, OFF, NULL);						
					}
					else if((buf[5]&0x18)==0x08){
						d->UPSPowerSupplyStatus.value.str = "逆变供电";
						Set_Var_Status(&d->UPSPowerSupplyStatus, ON, NULL);						
					}					
					else if((buf[5]&0x18)==0x10){
						d->UPSPowerSupplyStatus.value.str = "旁路供电";
						Set_Var_Status(&d->UPSPowerSupplyStatus, ON, NULL);						
					}						

					d->DiscontinuousSwitchPrompt.value.str				= buf[5]&0x20?"告警":"无告警";
					Set_Var_Status(&d->DiscontinuousSwitchPrompt,		  buf[5]&0x20?Alarm:Normal, NULL);
					d->InadequateStartupCapacity.value.str				= buf[6]&0x02?"告警":"无告警";
					Set_Var_Status(&d->InadequateStartupCapacity,		  buf[6]&0x02?Alarm:Normal, NULL);
					d->OverloadDelayShutdown.value.str					= buf[6]&0x04?"告警":"无告警";
					Set_Var_Status(&d->OverloadDelayShutdown,			  buf[6]&0x04?Alarm:Normal, NULL);
					d->LoadShockSwitchingBypass.value.str				= buf[6]&0x08?"告警":"无告警";
					Set_Var_Status(&d->LoadShockSwitchingBypass,		  buf[6]&0x08?Alarm:Normal, NULL);
					d->ParallelSwitchingBypass.value.str				= buf[6]&0x10?"告警":"无告警";
					Set_Var_Status(&d->ParallelSwitchingBypass,			  buf[6]&0x10?Alarm:Normal, NULL);
					d->BatteryLowVoltageShutdown.value.str				= buf[6]&0x20?"告警":"无告警";
					Set_Var_Status(&d->BatteryLowVoltageShutdown,		  buf[6]&0x20?Alarm:Normal, NULL);
					d->SwitchingTimesExhausted.value.str				= buf[6]&0x40?"告警":"无告警";
					Set_Var_Status(&d->SwitchingTimesExhausted,			  buf[6]&0x40?Alarm:Normal, NULL);
					break;
				case 3:
					d->RectifierFailure.value.str						= buf[3]&0x01?"故障":"无故障";
					Set_Var_Status(&d->RectifierFailure,				  buf[3]&0x01?Alarm:Normal, NULL);
					d->InverterFailure.value.str						= buf[3]&0x02?"故障":"无故障";
					Set_Var_Status(&d->InverterFailure,					  buf[3]&0x02?Alarm:Normal, NULL);
					d->AuxiliaryPowerFailure.value.str					= buf[3]&0x04?"故障":"无故障";
					Set_Var_Status(&d->AuxiliaryPowerFailure,			  buf[3]&0x04?Alarm:Normal, NULL);
					d->FanFailure.value.str								= buf[3]&0x08?"故障":"无故障";
					Set_Var_Status(&d->FanFailure,						  buf[3]&0x08?Alarm:Normal, NULL);
					d->InputThyristorFailure.value.str					= buf[3]&0x10?"故障":"无故障";
					Set_Var_Status(&d->InputThyristorFailure,			  buf[3]&0x10?Alarm:Normal, NULL);
					d->InverterThyristorFailure.value.str				= buf[3]&0x20?"故障":"无故障";
					Set_Var_Status(&d->InverterThyristorFailure,		  buf[3]&0x20?Alarm:Normal, NULL);
					d->BypassThyristorFailure.value.str					= buf[3]&0x40?"故障":"无故障";
					Set_Var_Status(&d->BypassThyristorFailure,			  buf[3]&0x40?Alarm:Normal, NULL);
					d->FuseBreak.value.str								= buf[3]&0x80?"故障":"无故障";
					Set_Var_Status(&d->FuseBreak,						  buf[3]&0x80?Alarm:Normal, NULL);
					d->BusVoltageAbnormal.value.str						= buf[4]&0x01?"故障":"无故障";
					Set_Var_Status(&d->BusVoltageAbnormal,				  buf[4]&0x01?Alarm:Normal, NULL);					
					d->InitializationFailure.value.str					= buf[4]&0x02?"故障":"无故障";
					Set_Var_Status(&d->InitializationFailure,			  buf[4]&0x02?Alarm:Normal, NULL);
					d->BatteryThyristorFailure.value.str				= buf[4]&0x04?"故障":"无故障";
					Set_Var_Status(&d->BatteryThyristorFailure,			  buf[4]&0x04?Alarm:Normal, NULL);
					d->ChargerFailure.value.str							= buf[4]&0x08?"故障":"无故障";
					Set_Var_Status(&d->ChargerFailure,					  buf[4]&0x08?Alarm:Normal, NULL);
					d->ParallelFailure.value.str						= buf[4]&0x10?"故障":"无故障";
					Set_Var_Status(&d->ParallelFailure,					  buf[4]&0x10?Alarm:Normal, NULL);

					d->InvalidBoot.value.str							= buf[4]&0x20?"报警":"无报警";
					Set_Var_Status(&d->InvalidBoot,						  buf[4]&0x20?Alarm:Normal, NULL);
					d->ITnverterDCComponentLarge.value.str				= buf[4]&0x40?"报警":"无报警";
					Set_Var_Status(&d->ITnverterDCComponentLarge,		  buf[4]&0x40?Alarm:Normal, NULL);
					d->InputPhaseReverse.value.str						= buf[4]&0x80?"报警":"无报警";
					Set_Var_Status(&d->InputPhaseReverse,				  buf[4]&0x80?Alarm:Normal, NULL);
					d->InputMissingZeroPhase.value.str					= buf[5]&0x01?"报警":"无报警";
					Set_Var_Status(&d->InputMissingZeroPhase,			  buf[5]&0x01?Alarm:Normal, NULL);
					d->BypassReverse.value.str							= buf[5]&0x02?"报警":"无报警";
					Set_Var_Status(&d->BypassReverse,					  buf[5]&0x02?Alarm:Normal, NULL);
					d->BatteryDamage.value.str							= buf[5]&0x20?"报警":"无报警";
					Set_Var_Status(&d->BatteryDamage,					  buf[5]&0x20?Alarm:Normal, NULL);
					d->BatteryOverheating.value.str						= buf[5]&0x40?"报警":"无报警";
					Set_Var_Status(&d->BatteryOverheating,				  buf[5]&0x40?Alarm:Normal, NULL);
					d->Overload.value.str								= buf[5]&0x80?"报警":"无报警";
					Set_Var_Status(&d->Overload,						  buf[5]&0x80?Alarm:Normal, NULL);
					d->ParallelOverload.value.str						= buf[6]&0x01?"报警":"无报警";
					Set_Var_Status(&d->ParallelOverload,				  buf[6]&0x01?Alarm:Normal, NULL);

					if((buf[6]&0x06)==0x00){
						d->BatteryVoltageAlarm.value.str = "无报警";
						Set_Var_Status(&d->BatteryVoltageAlarm, Normal, NULL);					
					}
					else if((buf[6]&0x06)==0x02){
						d->BatteryVoltageAlarm.value.str = "低压报警";
						Set_Var_Status(&d->BatteryVoltageAlarm, Alarm, NULL);				
					}					
					else if((buf[6]&0x06)==0x40){
						d->BatteryVoltageAlarm.value.str = "高压报警";
						Set_Var_Status(&d->BatteryVoltageAlarm, Alarm, NULL);					
					}

					d->BatteryUndervoltagePrealarm.value.str			= buf[6]&0x08?"报警":"无报警";
					Set_Var_Status(&d->BatteryUndervoltagePrealarm,		  buf[6]&0x08?Alarm:Normal, NULL);
					d->MainsFrequencyAbnormal.value.str					= buf[6]&0x10?"报警":"无报警";
					Set_Var_Status(&d->MainsFrequencyAbnormal,			  buf[6]&0x10?Alarm:Normal, NULL);
					d->MainsVoltageAbnormal.value.str					= buf[6]&0x20?"报警":"无报警";
					Set_Var_Status(&d->MainsVoltageAbnormal,			  buf[6]&0x20?Alarm:Normal, NULL);
					d->BypassSuperTracking.value.str					= buf[6]&0x40?"报警":"无报警";
					Set_Var_Status(&d->BypassSuperTracking,				  buf[6]&0x40?Alarm:Normal, NULL);
					d->BypassOvercurrent.value.str						= buf[7]&0x01?"报警":"无报警";
					Set_Var_Status(&d->BypassOvercurrent,				  buf[7]&0x01?Alarm:Normal, NULL);
					d->FireAlarm.value.str								= buf[7]&0x08?"报警":"无报警";
					Set_Var_Status(&d->FireAlarm,						  buf[7]&0x08?Alarm:Normal, NULL);
					d->SmokeAlarm.value.str								= buf[7]&0x10?"报警":"无报警";
					Set_Var_Status(&d->SmokeAlarm,						  buf[7]&0x10?Alarm:Normal, NULL);
					break;	
				default:
					break;
			}
			return 0;
		}
	}
	return 1;
}


/**********************************************************************************************************
* 函数名称： void ups_YMK3300_Registration(void)
* 函数说明： UPS监测驱动注册
* 输入参数： 无
* 返回参数： 无
**********************************************************************************************************/
void ups_YMK3300_Registration(void)
{
	DeviceRegWithResTimeout(
		"ups",													//设备类型
		"UPS监测",												//设备名称（导航栏默认显示名称）
		"YMK3300",												//设备型号
		"适用于科士达YMK3300系列三进三出高频模块化UPS。",//驱动描述
		var_attr,												//变量属性声明
		sizeof(Data_Struct),									//变量结构体空间大小
		cmd_fun,												//发送指令生成函数
		parse_fun,												//数据解析函数
		500													//设备响应超时时间
	);
#if 0 || VirtualFrameEN
	#define CMD1 "\x01\x04\x75\x30\x00\x29\x2B\xD7"
	#define RSP1 "\x01\x04\x52\x09\x1E\x09\x1B\x08\xFC\x01\xF3\x00\x11\x00\x14\x00\x12\x00\x5C\x00\x5B\x00\x5E\x08\x98\x08\x99\x08\x96\x01\xF4\x00\x00\x00\x00\x00\x30\x00\x00\x00\x00\x00\x08\x00\x00\x00\x00\x00\x10\x01\x0E\x00\xB4\x00\xBE\x09\x27\x09\x15\x08\xFA\x01\xF4\x08\x72\x08\x72\x00\x00\x00\x00\x00\x00\x00\x00\x00\x64\x03\x98\x00\x00\x00\x6E\x00\x00\x7E\x55"	
	#define CMD2 "\x01\x04\x75\x80\x00\x01\x2A\x2E"
	#define RSP2 "\x01\x04\x02\x00\x04\xB8\xF3"			
	#define CMD3 "\x01\x02\x27\x10\x00\x1F\x32\xB3"
	#define RSP3 "\x01\x02\x04\x33\xA4\x0F\x00\xB0\xB5"			
	#define CMD4 "\x01\x02\x27\x50\x00\x25\xB3\x74"
	#define RSP4 "\x01\x02\x05\x00\x00\x00\x00\x02\x23\x93"			
		
	VirtualFrameRegistration(CMD1, sizeof(CMD1)-1, RSP1, sizeof(RSP1)-1);
	VirtualFrameRegistration(CMD2, sizeof(CMD2)-1, RSP2, sizeof(RSP2)-1);
	VirtualFrameRegistration(CMD3, sizeof(CMD3)-1, RSP3, sizeof(RSP3)-1);
	VirtualFrameRegistration(CMD4, sizeof(CMD4)-1, RSP4, sizeof(RSP4)-1);	
#endif	
}

